﻿<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">

<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<body class="easyui-layout">
	<table id="role_list_table" class="easyui-treegrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="
		   	 rownumbers:true,
		   	 pageSize: 20,
			 pageList: [20,40,60],
		   	 pagination:true,
		   	 singleSelect:true,
		   	 animate: true,
           lines:true,
		   	 fitColumns : true,
		   	 url:'/menu-list-json',
           method:'get',
           idField: 'id',
           treeField: 'menuName',
           onBeforeLoad: function(row,param){
                if (!row) {	// load top level rows
                    param.id = 1;	// set id=0, indicate to load new page rows
              }
           },
           showFooter: true"
		>
		<thead>
			<tr>
				<th data-options="field:'menuName',width:90,align:'left'" >页面名称</th>
				<th data-options="field:'menuURL',width:90,align:'center'">页面路径</th>
				<th data-options="field:'menuIcon',width:90,align:'center'">图标</th>
				<th data-options="field:'parentId',width:90,align:'center' ,formatter:formatParent">类型</th>
			</tr>
		</thead>
	</table>


<!--  系统页面 -->
<div id="sys-menu" class="easyui-menu" style="width:150px;">
    <div id="sys-insert" data-options="iconCls:'icon-edit'" onclick="">新增父页面</div>
    <div class="menu-sep"></div>
</div>
<!-- 父页面右键 编辑状态-->
<div id="main-menu" class="easyui-menu" style="width:150px;">
	<div id="main-edit" data-options="iconCls:'icon-edit'" onclick="">编辑</div>
	<div id="main-delete" data-options="iconCls:'icon-edit'" onclick="">删除</div>
	<div class="menu-sep"></div>
	<div id="son-new" data-options="iconCls:'icon-add'">新增子页面</div>
</div>

<!-- 子页面右键 -->
<div id="son-menu" class="easyui-menu" style="width:150px;">
	<div id="son-edit" data-options="iconCls:'icon-edit'" onclick="">编辑</div>
	<div id="son-delete" data-options="iconCls:'icon-edit'" onclick="">删除</div>
	<div class="menu-sep"></div>
	<div id="btn-new" data-options="iconCls:'icon-add'">新增按钮</div>
</div>
<!-- 按钮右键 -->
<div id="button" class="easyui-menu" style="width:150px;">
	<div id="button-edit" data-options="iconCls:'icon-edit'" onclick="">编辑</div>
	<div id="button-delete" data-options="iconCls:'icon-edit'" onclick="">删除</div>
</div>
<script type="text/javascript">
	//增删改查-格式化
	function formatParent(value){
        if('0'==value){
            return '父页面';
        }else if('-1'==value){
            return '按钮'
		}else if('-3'==value){
            return ''
        }
        return'子页面';
	}
	//右键
    $("#role_list_table").treegrid({
        onContextMenu : function (e, rowIndex) {
            e.preventDefault();
            var row = $('#role_list_table').treegrid('getSelected');
            console.log(row.id);
            //可以删除
            if(row){
                //系统页面
                if(row.parentId=='-3'){
                    $('#sys-menu').menu('show',{
                        left : e.pageX,
                        top : e.pageY
                    });
                }
                //父页面
                if(row.parentId=='0'){
                    $('#main-menu').menu('show',{
                        left : e.pageX,
                        top : e.pageY
                    });

                //按钮
				}else if(row.parentId=='-1'){
                    $('#button').menu('show',{
                        left : e.pageX,
                        top : e.pageY
                    });
                //子页面
				}else if(row.parentId!='0'&&row.parentId!='-1'&&row.parentId!='-3'){
                    $('#son-menu').menu('show',{
                        left : e.pageX,
                        top : e.pageY
                    });
				}
                //不可删除
            }else {
                e.preventDefault();
            }
        }
    });
</script>

<script type="text/javascript">
	//父页面新增
    $("#sys-insert").click(function () {
        var url = '/admin-menu-add/main/-1';
        var index = layer.open({
            title:'菜单添加',
            type: 2,
            area: ['700px', '300px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });
	//父页面右键编辑
    $("#main-edit").click(function () {
        var row = $('#role_list_table').datagrid('getSelected');
        if (row){
            var url = '/admin-menu-add/main/'+row.id;
            var index = layer.open({
                title:'菜单添加',
                type: 2,
                area: ['700px', '300px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg('请选择需要编辑的角色', {icon: 2});
        }
    });
    //子页面右键编辑
	$('#son-edit').click(function(){
        var row = $('#role_list_table').datagrid('getSelected');
        var id = Number(row.id) - Number(1000);
        if (row){
            var url = '/admin-menu-add/son/'+id;
            var index = layer.open({
                title:'菜单添加',
                type: 2,
                area: ['700px', '300px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg('请选择需要编辑的角色', {icon: 2});
        }
	});


	//按钮新增
    $('#btn-new').click(function(){
        var row = $('#role_list_table').datagrid('getSelected');
        var menuId = Number(row.id) - Number(1000);
        var url = '/admin-button-add/-1?menuId='+menuId;
        var index = layer.open({
            title:'按钮信息',
            type: 2,
            area: ['700px', '450px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });
	//按钮右键编辑
	$('#button-edit').click(function(){
        var row = $('#role_list_table').datagrid('getSelected');
        var id = Number(row.id) - Number(2000);
        if (row){
            var url = '/admin-button-add/'+id;
            var index = layer.open({
                title:'按钮信息',
                type: 2,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: false,
                content: url
            });
        } else {
            layer.msg('请选择需要编辑的角色', {icon: 2});
        }
	});

	//新增子页面
    $('#son-new').click(function(){
        var row = $('#role_list_table').datagrid('getSelected');
        var url = '/admin-menu-add/son/-1?parentId='+row.id;
        var index = layer.open({
            title:'菜单添加',
            type: 2,
            area: ['700px', '300px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });


    //新增
    $('#add').click(function () {
        var url = '/admin-menu-add/-1';
        var index = layer.open({
            title:'菜单添加',
            type: 2,
            area: ['700px', '300px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    });
	//删除
	$("#main-delete").click(function () {
		var row = $('#role_list_table').datagrid('getSelected');
        layer.confirm('确定删除菜单？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/menu-delete',
                data : {id : row.id,tm : new Date().getTime()},
                async : false,
                success : function(){
                    $('#role_list_table').treegrid('reload');
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
	})
    $("#son-delete").click(function () {
        var row = $('#role_list_table').treegrid('getSelected');
        var id = Number(row.id) - Number(1000);
        layer.confirm('确定删除菜单？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/menu-delete',
                data : {id : id,tm : new Date().getTime()},
                async : false,
                success : function(data){
                    $('#role_list_table').treegrid('reload',data);
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
    })
    $("#button-delete").click(function () {
        var row = $('#role_list_table').treegrid('getSelected');
        var id = Number(row.id) - Number(2000);
        var parentId = '-3';
        layer.confirm('确定删除按钮？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/button-ins-upd-del/d',
                data : {id : id,tm : new Date().getTime()},
                async : false,
                success : function(data){
                    $('#role_list_table').treegrid('reload',data);
                }
            });
            layer.closeAll('dialog');
        }, function(){

        });
    })

</script>



